package com.ljb.xpdemo;

import android.content.Context;

import com.alibaba.fastjson.JSON;

import net.androidwing.hotxposed.IHookerDispatcher;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

/**
 * @author ljb
 * @des
 * @date 2019/8/19
 */
public class HookerDispatcher implements IHookerDispatcher {
    @Override
    public void dispatch(XC_LoadPackage.LoadPackageParam lpparam) {
        L.e("handleLoadPackage");
        if ("com.jrsen.android.rimet".equals(lpparam.packageName)) {
            L.e("发现了");
            XposedHelpers.findAndHookMethod("com.jrsen.android.rimet.d", lpparam.classLoader, "a", Context.class,
                    new XC_MethodHook() {
                        @Override
                        protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                            L.e("开始hook");
                        }

                        @Override
                        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                            L.e("hook结束");
                            Object result = param.getResult();
                            L.e("ret : " + result.toString());
//                            L.e("ret : " + new Gson().toJson(result));
                            L.e("ret:" + JSON.toJSONString(result));

                        }
                    });
        }
    }
}
